package com.daisuxia.back.service;

import static com.daisuxia.web.pojo.BorrowOrder.STATUS_BFHK;
import static com.daisuxia.web.pojo.BorrowOrder.STATUS_HKZ;
import static com.daisuxia.web.pojo.BorrowOrder.STATUS_YHK;
import static com.daisuxia.web.pojo.BorrowOrder.STATUS_YHZ;
import static com.daisuxia.web.pojo.BorrowOrder.STATUS_YQYHK;
import static com.daisuxia.web.pojo.BorrowOrder.STATUS_YYQ;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.daisuxia.back.dao.ISendMoneyStatisticDao;
import com.daisuxia.back.utils.ServiceResult;
import com.daisuxia.back.utils.SysCacheUtils;
import com.daisuxia.risk.service.IOutOrdersService;
import com.daisuxia.risk.service.IZmxyService;
import com.daisuxia.risk.service.IZzcService;
import com.daisuxia.ts.service.ITsOrdersService;
import com.daisuxia.web.dao.IBorrowAssetPacketDao;
import com.daisuxia.web.dao.IBorrowOrderCheckingDao;
import com.daisuxia.web.dao.IBorrowOrderCheckingExtDao;
import com.daisuxia.web.dao.IBorrowOrderDao;
import com.daisuxia.web.dao.IBorrowOrderLoanDao;
import com.daisuxia.web.dao.IBorrowOrderLoanPersonDao;
import com.daisuxia.web.dao.IBorrowStatisticsReportDao;
import com.daisuxia.web.dao.IRepaymentDao;
import com.daisuxia.web.dao.IUserDao;
import com.daisuxia.web.pojo.BackConfigParams;
import com.daisuxia.web.pojo.BorrowOrder;
import com.daisuxia.web.pojo.BorrowOrderChecking;
import com.daisuxia.web.pojo.Repayment;
import com.daisuxia.web.pojo.ReportRepayment;
import com.daisuxia.web.pojo.User;
import com.daisuxia.web.pojo.UserSendMessage;
import com.daisuxia.web.service.IBackConfigParamsService;
import com.daisuxia.web.service.IBorrowOrderService;
import com.daisuxia.web.service.IBorrowStatisticsReportService;
import com.daisuxia.web.service.IChannelReportService;
import com.daisuxia.web.service.ILoanMoneyReportService;
import com.daisuxia.web.service.ILoanReportService;
import com.daisuxia.web.service.IRenewalRecordService;
import com.daisuxia.web.service.IRepaymentDetailService;
import com.daisuxia.web.service.IRepaymentService;
import com.daisuxia.web.service.IReportRepaymentService;
import com.daisuxia.web.service.IThirdChannelReportService;
import com.daisuxia.web.service.IThreeLoanOrderService;
import com.daisuxia.web.service.IUserSendMessageService;
import com.daisuxia.web.service.IUserService;
import com.daisuxia.web.util.DateUtil;
import com.daisuxia.web.util.SendSmsUtil;
import com.sun.xml.bind.v2.TODO;

import net.sf.json.JSONObject;
import redis.clients.jedis.JedisCluster;

@Component("taskJob")
public class TaskJob implements ITaskJob {
	Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	JedisCluster jedisCluster;
	@Autowired
	private IRepaymentService repaymentService;
	@Autowired
	private IOutOrdersService outOrdersService;
	@Autowired
	private IRepaymentDao repaymentDao;
	@Autowired
	private IBorrowOrderDao borrowOrderDao;
	@Autowired
	private IUserDao userDao;
	@Autowired
	private IBorrowOrderCheckingDao borrowOrderCheckingDao;
	@Autowired
	private IBorrowOrderService borrowOrderService;
	@Autowired
	private IBorrowOrderLoanDao borrowOrderLoanDao;
	@Autowired
	private IBorrowOrderLoanPersonDao borrowOrderLoanPersonDao;
	@Autowired
	private IChannelReportService channelReportService;
	@Autowired
	private ILoanReportService loanReportService;
	@Autowired
	private IReportRepaymentService reportRepaymentService;
	@Autowired
	private IUserService userService;
	@Autowired
	private IRepaymentDetailService repaymentDetailService;
	@Autowired
	private IBackStatisticService backStatisticService;
	@Autowired
	private IBackConfigParamsService backConfigParamsService;
	@Autowired
	private IUserSendMessageService userSendMessageService;
	@Autowired
	private ISendMoneyStatisticDao sendMoneyStatisticDao;
	@Autowired
	private IBorrowStatisticsReportService borrowStatisticsReportService;
	@Autowired
	private ITsOrdersService tsOrdersService;
	@Autowired
	private IThirdChannelReportService thirdChannelReportService;
	@Autowired
	private IThreeLoanOrderService threeLoanOrderService;
	@Autowired
	private IBorrowStatisticsReportDao borrowStatisticsReportDao;

	@Autowired
	private IBorrowOrderCheckingExtDao borrowOrderCheckingExtDao;
	@Autowired
	private IBorrowAssetPacketDao borrowAssetPacketDao;
	@Autowired
	private IZmxyService zmservice;
	@Autowired
	private ILoanMoneyReportService loanMoneyReportService;
	@Autowired
	private IZzcService zzcService;
	@Autowired
	private IRenewalRecordService renewalRecordService;

	@Override
	public void updateRetry() {
		try {
			logger.info("retry send order");
			tsOrdersService.updateRetry();
		} catch (Exception e) {
			logger.error("retry send order error ", e);
		}
		try {
			logger.info("send user");
			tsOrdersService.sendSyReg();
		} catch (Exception e) {
			logger.error("send user error ", e);
		}
	}

	@Override
	public void overdue() {
		logger.error("逾期任务开始---------->overdue start");
		Map<String, Object> params = new HashMap<String, Object>();
		Integer statuses[] = new Integer[] { STATUS_HKZ, STATUS_BFHK, STATUS_YYQ, STATUS_YHZ };
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String repaymentTimeEnd = dateFormat.format(date);

		params.put("statuses", statuses);
		params.put("repaymentTimeEnd", repaymentTimeEnd);
		List<Repayment> repaymentList = repaymentService.findTaskRepayment(params);
		for (Repayment re : repaymentList) {
			Repayment repayment = repaymentService.selectByPrimaryKey(re.getId());
			if (!repayment.getStatus().equals(BorrowOrder.STATUS_YHK)
					&& !repayment.getStatus().equals(BorrowOrder.STATUS_YQYHK)) {
				repaymentService.overdue(repayment);
				// tsOrdersService.sendBorrowStatus(repayment.getAssetOrderId());
			}
		}
		logger.error("逾期任务结束---------->overdue end 共 " + repaymentList.size());
	}

	/**
	 * 短信提醒
	 */
	@Override
	public void repaySmsRemind() {
		logger.error("短信提醒任务开始---------->repaySmsRemind start");
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String repaymentTimeStart = dateFormat.format(DateUtil.addDay(date, 1));
		String repaymentTimeEnd = dateFormat.format(DateUtil.addDay(date, 2));
		// String repaymentTimeStart = "2017-01-11";
		// String repaymentTimeEnd = "2017-01-12";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("repaymentTimeStart", repaymentTimeStart);
		params.put("repaymentTimeEnd", repaymentTimeEnd);
		Integer[] statuses = new Integer[] { STATUS_HKZ };
		params.put("statuses", statuses);
		List<Repayment> repayments = repaymentService.findByRepaymentSmsRemind(params);
		for (Repayment re : repayments) {
			try {
				Map<String, String> user = repaymentService.findUserPhoneName(re.getUserId());
				Map<String, String> card = repaymentService.findCardNo(re.getUserId());
				String cardNo = card.get("cardNo");
				String content = "尊敬的" + user.get("realname") + "，您的" + (re.getRepaymentAmount() / 100)
						+ "借款明日到期，请至APP还款，若到期未还款，平台将自动扣款，请确保尾号" + cardNo.substring(cardNo.length() - 4)
						+ "银行卡资金充足，以免产生逾期。如已还款，请忽略。";
				SendSmsUtil.sendSmsDiyCL(user.get("userPhone"), content);
				UserSendMessage message = new UserSendMessage();
				message.setPhone(user.get("userPhone"));// 接收的用户
				message.setMessageCreateTime(new Date());
				message.setMessageContent(content);
				message.setMessageStatus(UserSendMessage.STATUS_SUCCESS);// 发送成功
				// 2
				userSendMessageService.saveUserSendMsg(message);// 添加短息记录
			} catch (Exception e) {
				logger.error("sendsms error ", e);
			}

		}
		logger.error("短信提醒任务结束---------->repaySmsRemind end 共 " + repayments.size());
	}

	/**
	 * 短信提醒当日
	 */
	@Override
	public void repaySmsRemind9() {
		logger.error("短信当日提醒任务开始---------->repaySmsRemind start");
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String repaymentTimeStart = dateFormat.format(date);
		String repaymentTimeEnd = dateFormat.format(DateUtil.addDay(date, 1));
		// String repaymentTimeStart = "2017-01-11";
		// String repaymentTimeEnd = "2017-01-12";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("repaymentTimeStart", repaymentTimeStart);
		params.put("repaymentTimeEnd", repaymentTimeEnd);
		Integer[] statuses = new Integer[] { STATUS_HKZ };
		params.put("statuses", statuses);
		List<Repayment> repayments = repaymentService.findByRepaymentSmsRemind(params);
		for (Repayment re : repayments) {
			try {
				Map<String, String> user = repaymentService.findUserPhoneName(re.getUserId());
				Map<String, String> card = repaymentService.findCardNo(re.getUserId());
				String cardNo = card.get("cardNo");
				String content = "尊敬的" + user.get("realname") + "，您的" + (re.getRepaymentAmount() / 100)
						+ "借款今日到期，请至APP还款，若到期未还款，平台将自动扣款，请确保尾号" + cardNo.substring(cardNo.length() - 4)
						+ "银行卡资金充足，以免产生逾期。如已还款，请忽略。";
				SendSmsUtil.sendSmsDiyCL(user.get("userPhone"), content);
				UserSendMessage message = new UserSendMessage();
				message.setPhone(user.get("userPhone"));// 接收的用户
				message.setMessageCreateTime(new Date());
				message.setMessageContent(content);
				message.setMessageStatus(UserSendMessage.STATUS_SUCCESS);// 发送成功
				// 2
				userSendMessageService.saveUserSendMsg(message);// 添加短息记录
			} catch (Exception e) {
				logger.error("sendsms error ", e);
			}

		}
		logger.error("短信当日提醒任务结束---------->repaySmsRemind end 共 " + repayments.size());
	}

	/**
	 * 代扣 现金贷平台不适用代扣
	 */
	//TODO-ZSH
	@Override
	public void withhold() {
/*		logger.error("代扣任务开始---------->withhold start");

		try {
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
			Date date = new Date();
			String repaymentTime = dateFormat.format(date);
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("repaymentTime", repaymentTime);
			Integer[] statuses = new Integer[] { STATUS_HKZ };
			params.put("statuses", statuses);
			List<Repayment> repayments = repaymentService.findTaskRepayment(params);
			logger.error("代扣数量 withhold count " + repayments.size());
			ThreadPool pool = ThreadPool.getInstance();
			for (Repayment repayment : repayments) {
				String redis_repay_id = jedisCluster.get("REPAYMENT_REPAY_WITHHOLD_" + repayment.getId());
				if ("true".equals(redis_repay_id)) {
					pool.execute(new WithholdThread(logger, repayment.getId(), repaymentTime, dateFormat, userService,
							repaymentService, repaymentDetailService, borrowOrderService, jedisCluster));
				}

				
				 * Repayment re = repaymentService.selectByPrimaryKey(repayment.getId());
				 * if(dateFormat .format(re.getRepaymentTime()).equals(repaymentTime) &&
				 * re.getStatus().equals(BorrowOrder.STATUS_HKZ)){ try {
				 * logger.error("代扣开始 withhold userId = " + repayment.getUserId()); User user =
				 * userService.searchByUserid(re.getUserId()); ServiceResult result =
				 * repaymentService.withhold(re, user, Repayment.TASK_WITHHOLD); if
				 * (result.getCode().equals(ServiceResult.SUCCESS)) { RepaymentDetail detail =
				 * new RepaymentDetail(); detail.setUserId(re.getUserId());
				 * detail.setAssetRepaymentId(re.getId());
				 * detail.setTrueRepaymentMoney(re.getRepaymentAmount() -
				 * re.getRepaymentedAmount()); detail.setCreatedAt(new Date());
				 * detail.setOrderId(result.getExt().toString());
				 * detail.setRepaymentType(RepaymentDetail.TYPE_BANK_CARD_AUTO);
				 * detail.setRemark("定时任务代扣"); detail.setUserId(re.getUserId());
				 * detail.setUpdatedAt(new Date());
				 * detail.setStatus(RepaymentDetail.STATUS_SUC);
				 * detail.setAssetOrderId(re.getAssetOrderId());
				 * repaymentDetailService.insertSelective(detail); repaymentService.repay(re,
				 * detail);
				 *
				 * // 如果是未逾期的还款，调用提额 if (re.getLateDay() == 0) {
				 * logger.error("repay to Mention Money ing ----------------->" );
				 * borrowOrderService.addUserLimit(user); } } } catch (Exception e) {
				 * logger.error("repay withhold error repaymentId = " + repayment.getId(), e); }
				 
				// }
			}
		} catch (Exception e) {
			logger.error("repay withhold error ：", e);
		}
		logger.error("代扣任务结束---------->withhold end 共 ");*/
	}

	@Override
	public void reportRepayment(String firstRepaymentTime, boolean showOverdute) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		logger.error("每日还款、逾期报表任务开始---------->reportRepayment start " + firstRepaymentTime + " " + showOverdute);
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("firstRepaymentTime", firstRepaymentTime);
		List<Repayment> repayments = repaymentService.findByRepaymentReport(params);

		// 逾期、正常还款、部分还款
		Long expireAmount = 0L; // 到期金额
		Long expireCount = (long) repayments.size(); // 总数量
		Long overdueAmount = 0L; // 新增逾期金额
		Long overdueCount = 0L; // 逾期数量
		Long overdueCountSeven = 0L; // 逾期7天数量
		Long overdueAmountSeven = 0L; // 逾期7天金额
		Long overdueCountFourteen = 0L; // 逾期14天数量
		Long overdueAmountFourteen = 0L; // 逾期14天金额
		Long countSeven = 0L; // 7天数量
		Long countFourteen = 0L; // 14天数量
		Long amountSeven = 0L; // 7天金额
		Long amountFourteen = 0L; // 14天金额
		Long repayCount = 0L; // 今日还款数量
		Long repayAmount = 0L; // 今日还款金额
		Long oldOverdueCount = 0L; // 今日老用户逾期数量
		Long oldOverdueAmount = 0L; // 今日老用户逾期金额
		Long newOverdueCount = 0L; // 今日新用户逾期数量
		Long newOverdueAmount = 0L; // 今日新用户逾期金额
		Long oldRepayCount = 0L; // 今日老用户还款数量
		Long oldRepayAmount = 0L; // 今日老用户还款金额
		Long newRepayCount = 0L; // 今日新用户还款数量
		Long newRepayAmount = 0L; // 今日新用户还款金额
		Long newExpireAmount = 0L; // 今日新用户到期金额
		Long newExpireCount = 0L; // 今日新用户到期数量
		Long oldExpireAmount = 0L; // 今日老用户到期金额
		Long oldExpireCount = 0L; // 今日老用户到期数量

		for (Repayment re : repayments) {
			int moneyAmount = (int) (re.getRepaymentPrincipal() + re.getRepaymentInterest());
			int status = re.getStatus();
			String repaymentTime = dateFormat.format(re.getRepaymentTime());
			String firstRepayment = dateFormat.format(re.getFirstRepaymentTime());
			if (status == STATUS_YHK || !repaymentTime.equals(firstRepayment)) {
				// 新增还款金额 还款数量
				repayAmount += moneyAmount;
				repayCount++;
				// 新旧用户已还数量
				if (User.CUSTOMER_OLD.equals(String.valueOf(re.getCustomerType()))) {
					oldRepayCount++;
					oldRepayAmount += moneyAmount;
				} else {
					newRepayCount++;
					newRepayAmount += moneyAmount;
				}
			} else {
				// 新增逾期金额 逾期数量
				overdueAmount += moneyAmount;
				overdueCount++;
				// 新旧用户逾期数量 逾期金额
				if (User.CUSTOMER_OLD.equals(String.valueOf(re.getCustomerType()))) {
					oldOverdueCount++;
					oldOverdueAmount += moneyAmount;
				} else {
					newOverdueCount++;
					newOverdueAmount += moneyAmount;
				}
				// 7天14天逾期数量
				if (re.getLoanTerm() == 7) {
					overdueCountSeven++;
					overdueAmountSeven += moneyAmount;
				} else {
					overdueCountFourteen++;
					overdueAmountFourteen += moneyAmount;
				}
			}
			// 计算总数量
			if (re.getLoanTerm() == 7) {
				countSeven++;
				amountSeven += moneyAmount;
			} else {
				countFourteen++;
				amountFourteen += moneyAmount;
			}
			// 到期金额
			expireAmount += moneyAmount;
			// 新老用户到期金额
			if (User.CUSTOMER_OLD.equals(String.valueOf(re.getCustomerType()))) {
				oldExpireAmount += moneyAmount;
				oldExpireCount++;
			} else {
				newExpireAmount += moneyAmount;
				newExpireCount++;
			}
		}

		List<Map<String, Object>> renewals = reportRepaymentService.findRenewalByRepaymentReport(params);
		expireCount += renewals.size();
		for (Map<String, Object> renewal : renewals) {
			String repaymentTime = dateFormat.format(renewal.get("repaymentTime"));
			String repaymentTimeRe = dateFormat.format(renewal.get("repaymentTimeRe"));
			int moneyAmount = Integer.parseInt(renewal.get("moneyAmount").toString());
			int status = Integer.parseInt(renewal.get("status").toString());
			int loanTerm = Integer.parseInt(renewal.get("loanTerm").toString());
			if (status == STATUS_YHK || !repaymentTime.equals(repaymentTimeRe)) {
				// 新增还款金额 还款数量
				repayAmount += moneyAmount;
				repayCount++;
				// 旧用户已还数量
				oldRepayCount++;
				oldRepayAmount += moneyAmount;
			} else {
				// 新增逾期金额 逾期数量
				overdueAmount += moneyAmount;
				overdueCount++;
				// 旧用户逾期数量 逾期金额
				oldOverdueCount++;
				oldOverdueAmount += moneyAmount;
				// 7天14天逾期数量
				if (loanTerm == 7) {
					overdueCountSeven++;
					overdueAmountSeven += moneyAmount;
				} else {
					overdueCountFourteen++;
					overdueAmountFourteen += moneyAmount;
				}
			}
			// 计算总数量
			if (loanTerm == 7) {
				countSeven++;
				amountSeven += moneyAmount;
			} else {
				countFourteen++;
				amountFourteen += moneyAmount;
			}
			// 到期金额
			expireAmount += moneyAmount;
			// 老用户到期金额
			oldExpireAmount += moneyAmount;
			oldExpireCount++;
		}

		ReportRepayment report = new ReportRepayment();
		report.setReportDate(firstRepaymentTime);
		if (expireCount > 0) {
			if (showOverdute) {
				report.setOverdueRate(overdueCount * 10000 / expireCount);
				if (countSeven > 0) {
					report.setOverdueRateSeven(overdueCountSeven * 10000 / countSeven);
				}
				if (countFourteen > 0) {
					report.setOverdueRateFourteen(overdueCountFourteen * 10000 / countFourteen);
				}
				if (oldExpireCount > 0) {
					report.setOverdueRateOld(oldOverdueCount * 10000 / oldExpireCount);
				}
				if (newExpireCount > 0) {
					report.setOverdueRateNew(newOverdueCount * 10000 / newExpireCount);
				}

				report.setOverdueAmount(overdueAmount);
				report.setOverdueRateAmount(overdueAmount * 10000 / expireAmount);
				if (amountSeven > 0) {
					report.setOverdueRateSevenAmount(overdueAmountSeven * 10000 / amountSeven);
				}
				if (amountFourteen > 0) {
					report.setOverdueRateFourteenAmount(overdueAmountFourteen * 10000 / amountFourteen);
				}
				report.setOverdueAmountOld(oldOverdueAmount);
				report.setOverdueAmountNew(newOverdueAmount);
				if (oldExpireAmount > 0) {
					report.setOverdueRateOldAmount(oldOverdueAmount * 10000 / oldExpireAmount);
				}
				if (newExpireAmount > 0) {
					report.setOverdueRateNewAmount(newOverdueAmount * 10000 / newExpireAmount);
				}
			}
			report.setRepayRate(repayCount * 10000 / expireCount);

			if (oldExpireCount > 0) {
				report.setRepayRateOld(oldRepayCount * 10000 / oldExpireCount);
			}
			if (newExpireCount > 0) {
				report.setRepayRateNew(newRepayCount * 10000 / newExpireCount);
			}

			report.setExpireAmount(expireAmount);

			report.setExpireAmountOld(oldExpireAmount);
			report.setExpireAmountNew(newExpireAmount);

			report.setRepayRateAmount(repayAmount * 10000 / expireAmount);
			if (oldExpireAmount > 0) {
				report.setRepayRateOldAmount(oldRepayAmount * 10000 / oldExpireAmount);
			}
			if (newExpireAmount > 0) {
				report.setRepayRateNewAmount(newRepayAmount * 10000 / newExpireAmount);
			}
		}

		params.clear();
		Integer[] statuses = new Integer[] { STATUS_HKZ, STATUS_BFHK, STATUS_YHZ, STATUS_YYQ, STATUS_YHK,
				STATUS_YQYHK };
		params.put("statuses", statuses);
		params.put("firstRepaymentTimeEnd", firstRepaymentTime);
		// repayments = repaymentService.findByRepaymentReport(params);

		Long allCount = 0L; // 总借款数量
		Long allAmount = 0L; // 总借款金额
		Long allBorrowCount = 0L; // 当前借款数量
		Long allBorrowAmount = 0L; // 当前借款金额
		Long allRepayCount = 0L; // 当前还款数量
		Long allRepayAmount = 0L; // 当前还款金额
		Long allOverdueCount = 0L; // 当前逾期数量
		Long allOverdueAmount = 0L; // 当前逾期金额
		Long overdueS1Count = 0L; // 当前逾期S1数量
		Long overdueS1Amount = 0L; // 当前逾期S1金额
		Long overdueS2Count = 0L; // 当前逾期S2数量
		Long overdueS2Amount = 0L; // 当前逾期S2金额
		Long overdueS3Count = 0L; // 当前逾期S3数量
		Long overdueS3Amount = 0L; // 当前逾期S3金额
		Long overdueM3Count = 0L; // 当前逾期M3数量
		Long overdueM3Amount = 0L; // 当前逾期M3金额

		// 总借款数量、金额
		Map<String, Object> map = reportRepaymentService.findAllByReport(firstRepaymentTime);
		allCount += (Long) map.get("countAll");
		if(map.get("amountAll")!=null) {
		    allAmount += ((BigDecimal) map.get("amountAll")).longValue();
		}
		map = reportRepaymentService.findAllRenewalByReport(firstRepaymentTime);
		allCount += (Long) map.get("countAll");
		if(map.get("amountAll")!=null) {
			allAmount += ((BigDecimal) map.get("amountAll")).longValue();
		}
		// 当前借款数量、金额
		map = reportRepaymentService.findAllBorrowByReport(firstRepaymentTime);
		allBorrowCount += (Long) map.get("countAll");
		if(map.get("amountAll")!=null) {
			allBorrowAmount += ((BigDecimal) map.get("amountAll")).longValue();
		}
		map = reportRepaymentService.findAllRenewalBorrowByReport(firstRepaymentTime);
		allBorrowCount += (Long) map.get("countAll");
		if(map.get("amountAll")!=null) {
			allBorrowAmount += ((BigDecimal) map.get("amountAll")).longValue();
		}
		// 当前还款数量、金额
		map = reportRepaymentService.findAllRepayByReport(firstRepaymentTime);
		allRepayCount += (Long) map.get("countAll");
		if(map.get("amountAll")!=null) {
			allRepayAmount += ((BigDecimal) map.get("amountAll")).longValue();
		}
		map = reportRepaymentService.findAllRenewalRepayByReport(firstRepaymentTime);
		allRepayCount += (Long) map.get("countAll");
		if(map.get("amountAll")!=null) {
			allRepayAmount += ((BigDecimal) map.get("amountAll")).longValue(); 
		} 
		// 当前逾期数量、金额
		map = reportRepaymentService.findAllOverdueByReport(firstRepaymentTime);
		allOverdueCount += (Long) map.get("countAll");
		if(map.get("amountAll")!=null) {
			allOverdueAmount += ((BigDecimal) map.get("amountAll")).longValue();
	    }
		// S1S2S3数量、金额
		params.clear();
		params.put("reportTime", firstRepaymentTime);
		params.put("reportTimeOneHour", firstRepaymentTime + " 01:00:00");
		List<Map<String, Object>> list = reportRepaymentService.findOverdueRateSByReport(params);

		for (Map<String, Object> temp : list) {
			long lateDay = Long.parseLong(temp.get("lateDay").toString());
			long countAll = (Long) temp.get("countAll");
			long amountAll = ((BigDecimal) temp.get("amountAll")).longValue();
			if (lateDay > 0 && lateDay <= 10) {
				overdueS1Count += countAll;
				overdueS1Amount += amountAll;
			} else if (lateDay > 10 && lateDay <= 30) {
				overdueS2Count += countAll;
				overdueS2Amount += amountAll;
			} else if (lateDay > 30 && lateDay <= 60) {
				overdueS3Count += countAll;
				overdueS3Amount += amountAll;
			} else if (lateDay > 60 && lateDay <= 90) {
				overdueM3Count += countAll;
				overdueM3Amount += amountAll;
			}
		}

		/*
		 * for (Repayment re : repayments) { int status = re.getStatus(); int
		 * moneyAmount = (int) (re.getRepaymentPrincipal() + re.getRepaymentInterest());
		 * allCount++; allAmount += moneyAmount; // 还款完成金额、数量 if (STATUS_YHK == status
		 * || STATUS_YQYHK == status) { allRepayCount++; allRepayAmount += moneyAmount;
		 * } else { // 当前借款金额、数量 allBorrowCount++; allBorrowAmount += moneyAmount; //
		 * 逾期中数量、金额 if (STATUS_YYQ == status) { allOverdueCount++; allOverdueAmount +=
		 * moneyAmount;
		 *
		 * if (re.getLateDay() > 0 && re.getLateDay() <= 10) { overdueS1Count++;
		 * overdueS1Amount += moneyAmount; } else if (re.getLateDay() > 10 &&
		 * re.getLateDay() <= 30) { overdueS2Count++; overdueS2Amount += moneyAmount; }
		 * else if (re.getLateDay() > 30 && re.getLateDay() <= 60) { overdueS3Count++;
		 * overdueS3Amount += moneyAmount; } } } }
		 *
		 * renewals = reportRepaymentService.findRenewalByRepaymentReport(params); for
		 * (Map<String, Object> renewal : renewals) { int moneyAmount =
		 * Integer.parseInt(renewal.get("moneyAmount").toString()); int status =
		 * Integer.parseInt(renewal.get("status").toString()); int lateDay =
		 * Integer.parseInt(renewal.get("lateDay").toString()); allCount++; allAmount +=
		 * moneyAmount; // 还款完成金额、数量 if (STATUS_YHK == status || STATUS_YQYHK == status)
		 * { allRepayCount++; allRepayAmount += moneyAmount; } else { // 当前借款金额、数量
		 * allBorrowCount++; allBorrowAmount += moneyAmount; // 逾期中数量、金额 if (STATUS_YYQ
		 * == status) { allOverdueCount++; allOverdueAmount += moneyAmount;
		 *
		 * if (lateDay > 0 && lateDay <= 10) { overdueS1Count++; overdueS1Amount +=
		 * moneyAmount; } else if (lateDay > 10 && lateDay <= 30) { overdueS2Count++;
		 * overdueS2Amount += moneyAmount; } else if (lateDay > 30 && lateDay <= 60) {
		 * overdueS3Count++; overdueS3Amount += moneyAmount; } } } }
		 */

		if (allCount > 0) {
			report.setAllBorrowCount(allBorrowCount);
			report.setAllBorrowAmount(allBorrowAmount);
			report.setAllRepayCount(allRepayCount);
			report.setAllRepayAmount(allRepayAmount);
			report.setAllOverdueCount(allOverdueCount);
			report.setAllOverdueAmount(allOverdueAmount);
			report.setOverdueRateS1Count(overdueS1Count * 10000 / allCount);
			report.setOverdueRateS1Amount(overdueS1Amount * 10000 / allAmount);
			report.setOverdueRateS2Count(overdueS2Count * 10000 / allCount);
			report.setOverdueRateS2Amount(overdueS2Amount * 10000 / allAmount);
			report.setOverdueRateS3Count(overdueS3Count * 10000 / allCount);
			report.setOverdueRateS3Amount(overdueS3Amount * 10000 / allAmount);
			report.setOverdueRateM3Count(overdueM3Count * 10000 / allCount);
			report.setOverdueRateM3Amount(overdueM3Amount * 10000 / allAmount);
		}

		Integer id = reportRepaymentService.findIdByDate(report.getReportDate());
		if (null == id) {
			reportRepaymentService.insertSelective(report);
		} else {
			report.setId(id);
			reportRepaymentService.updateByPrimaryKeySelective(report);
		}

		logger.error("每日还款、逾期报表任务结束---------->reportRepayment end " + firstRepaymentTime);
	}

	/**
	 * 每日还款、逾期报表 中午12点
	 */
	@Override
	public void reportRepayment12() {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String firstRepaymentTime;
		Calendar now = Calendar.getInstance();
		now.add(Calendar.DAY_OF_YEAR, -1);
		firstRepaymentTime = dateFormat.format(now.getTime());
		// 12点后的定时 更新前一日数据 （带逾期信息）
		reportRepayment(firstRepaymentTime, true);
	}

	/**
	 * 每日还款、逾期报表 每两个小时
	 */
	@Override
	public void reportRepaymentE2() {
		// ZCM每两个小时查询明天资产包信息 zjb
		// try {
		// assetsDivisionExt();
		// Date nowDate = new Date();
		// String nextDate = DateUtil.getDateFormat(DateUtil.addDay(nowDate,
		// 1), "yyyy-MM-dd");
		// borrowOrderService.assetpackqueryZCM(nextDate);
		// } catch (Exception e) {
		//
		// }
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String firstRepaymentTime;
		Calendar now = Calendar.getInstance();
		// 12点后 只更新当日 （不带逾期信息）
		if (now.get(Calendar.HOUR_OF_DAY) >= 4) {
			firstRepaymentTime = dateFormat.format(now.getTime());
			reportRepayment(firstRepaymentTime, false);
		}
		// 12点前 更新昨日、当日 （不带逾期信息）
		else {
			firstRepaymentTime = dateFormat.format(now.getTime());
			reportRepayment(firstRepaymentTime, false);

			now.add(Calendar.DAY_OF_YEAR, -1);
			firstRepaymentTime = dateFormat.format(now.getTime());
			reportRepayment(firstRepaymentTime, false);
		}

	}
	//TODO-ZSH
	@Override
	public void queryPaysStateNotCmb() {
	/*	if (!PropertiesUtil.get("CMB_ISRUN").equals("YES")) {
			logger.error("cmb total is close so   queryPaysStateNotCmb is close");
			return;
		}
		logger.error("queryPaysStateNotCmb  starting ");
		try {
			int allAccounts[] = BorrowOrder.LOAN_ACCOUNTS;
			for (int curLoanAccount : allAccounts) {// 查询多个ukey的信息

				String orderNo = GenerateNo.nextOrdId();
				HashMap<String, String> hLAccountInfo = borrowOrderService.getHLAccountInfo(curLoanAccount);
				if (!hLAccountInfo.get("HL_ISOPEN").equals("1")) {
					logger.error("account:" + curLoanAccount
							+ "=====Hulian   is close queryPaysStateNotCmb is stop 账户网银互联功能已关闭！");
					break;
				}
				// 生成请求报文
				String requestParams = HttpRequestCMBHL.getRequestNTQRYEBPStr(hLAccountInfo);
				System.out.println(requestParams);
				String tablelastName = DateUtil.getDateFormat(new Date(), "yyyyMMdd");
				// 插入订单
				OutOrders orders = new OutOrders();
				orders.setOrderNo(orderNo);
				orders.setOrderType(OutOrders.orderType_cmb);
				// orders.setAssetOrderId(borrowOrder.getId());
				orders.setReqParams(requestParams);
				orders.setAddTime(new Date());
				orders.setAct("NTQRYEBP");
				orders.setStatus(OutOrders.STATUS_WAIT);
				orders.setTablelastName(tablelastName);
				outOrdersService.insertByTablelastName(orders);
				String goUrl = hLAccountInfo.get("HL_URL");
				// 连接前置机，发送请求报文，获得返回报文
				String result = HttpRequestCMBHL.sendRequest(requestParams, goUrl);
				// 更新订单
				OutOrders ordersNew = new OutOrders();
				ordersNew.setId(orders.getId());
				ordersNew.setOrderNo(orderNo);
				ordersNew.setReturnParams(result);
				ordersNew.setUpdateTime(new Date());
				ordersNew.setStatus(OutOrders.STATUS_SUC);
				ordersNew.setTablelastName(tablelastName);
				outOrdersService.updateByTablelastName(ordersNew);

				if (result != null && result.length() > 0) {

					String jsonstring = HttpRequestCMBDF.xml2JSON(result);

					JSONObject jsonObj = JSONObject.fromObject(jsonstring);
					// JSONArray arrays = jsonObj.getJSONArray("NTWAUEBPZ");

					Object objj = jsonObj.get("NTWAUEBPZ");
					JSONArray arrays = null;
					if (objj instanceof JSONObject) {
						arrays = new JSONArray();
						arrays.add(objj);
					} else if (objj instanceof JSONArray) {
						arrays = jsonObj.getJSONArray("NTWAUEBPZ");
					}

					if (arrays != null && arrays.size() > 0) {

						for (int i = 0; i < arrays.size(); i++) {
							JSONObject obj = arrays.getJSONObject(i);

							String sREQSTS = obj.getString("REQSTS");
							String sRTNFLG = "";
							if (obj.containsKey("RTNFLG")) {
								sRTNFLG = obj.getString("RTNFLG");
							}

							String sYURREF = obj.getString("YURREF");// 业务号

							if (StringUtils.isNotBlank(sYURREF)) {
								ServiceResult serviceResult = getPayNotCmbresult(obj, sREQSTS, sRTNFLG);
								String code = serviceResult.getCode();
								String payRemark = serviceResult.getMsg();
								HashMap<String, Object> params = new HashMap<String, Object>();
								params.put("notPayStatus", BorrowOrder.SUB_PAY_SUCC);
								params.put("yurref", sYURREF);
								Date nowDate = new Date();
								String sOPRDAT = null;
								Date zhfkDate = null;// 真正的放款时间
								if (obj.containsKey("OPRDAT")) {
									sOPRDAT = obj.getString("OPRDAT");
									zhfkDate = DateUtil.cmbToDateByString(sOPRDAT);
								}

								if (sYURREF.startsWith("A")) {

									BorrowOrder borrowOrder = null;

									borrowOrder = borrowOrderDao.selectByParam(params);

									if (borrowOrder != null
											&& !borrowOrder.getPaystatus().equals(BorrowOrder.SUB_PAY_SUCC)
											&& borrowOrder.getStatus() == BorrowOrder.STATUS_FKZ) {

										BorrowOrder borrowOrderNew = new BorrowOrder();
										borrowOrderNew.setId(borrowOrder.getId());
										// borrowOrderNew.setPaystatus(paystatus);
										borrowOrderNew.setPayRemark(payRemark);
										borrowOrderNew.setUpdatedAt(nowDate);

										if (code.equals(BorrowOrder.SUB_PAY_SUCC)) {
											borrowOrderNew.setCapitalType(curLoanAccount);
											borrowOrderNew.setPaystatus(code);
											borrowOrderNew.setLoanTime(zhfkDate);
											borrowOrderNew.setStatus(BorrowOrder.STATUS_HKZ);
											borrowOrderNew.setLoanEndTime(
													DateUtil.addDay(zhfkDate, borrowOrder.getLoanTerm()));// 放款时间加上借款期限

											// 放款成功插入还款记录
											borrowOrder.setPaystatus(code);
											borrowOrder.setStatus(BorrowOrder.STATUS_HKZ);
											borrowOrder.setLoanTime(zhfkDate);
											borrowOrder.setLoanEndTime(borrowOrderNew.getLoanEndTime());// 放款时间加上借款期限

											repaymentService.insertByBorrorOrder(borrowOrder);
											// 插入资产信息
											if (curLoanAccount == BorrowOrder.LOAN_ACCOUNT2) {
												borrowOrderService.addBorrowCheckingExt(borrowOrder);
											} else {
												borrowOrderService.addBorrowChecking(borrowOrder);
											}

											// 设置B可打款
											params.clear();
											params.put("assetOrderId", borrowOrder.getId());
											params.put("status", BorrowOrderLoan.CSZT);
											params.put("noPayStatus", BorrowOrder.SUB_PAY_SUCC);
											BorrowOrderLoan bdl = borrowOrderLoanDao.selectByParam(params);
											if (bdl != null) {
												BorrowOrderLoan bdlNew = new BorrowOrderLoan();
												bdlNew.setId(bdl.getId());
												bdlNew.setUpdatedAt(nowDate);
												bdlNew.setCapitalType(curLoanAccount);// 设置资产归属
												bdlNew.setStatus(BorrowOrderLoan.DFK);
												bdlNew.setCreatedAt(zhfkDate);
												borrowOrderLoanDao.updateByPrimaryKeySelective(bdlNew);
											}
											// 设置C可打款
											BorrowOrderLoanPerson bdlPerson = borrowOrderLoanPersonDao
													.selectByParam(params);
											BorrowOrderLoanPerson bdlPersonNew = new BorrowOrderLoanPerson();
											if (bdlPerson != null) {
												bdlPersonNew.setId(bdlPerson.getId());
												bdlPersonNew.setUpdatedAt(nowDate);
												bdlPersonNew.setCapitalType(curLoanAccount);// 设置资产归属
												bdlPersonNew.setStatus(BorrowOrderLoan.DFK);
												bdlPersonNew.setCreatedAt(zhfkDate);
												borrowOrderLoanPersonDao.updateByPrimaryKeySelective(bdlPersonNew);
											}
										} else if (code.equals(BorrowOrder.PAY_PAY_FAIL)) {

											borrowOrderNew.setPaystatus(code);
											borrowOrderNew.setStatus(BorrowOrder.STATUS_FKSB);
										}
										borrowOrderDao.updateByPrimaryKeySelective(borrowOrderNew);
										// tsOrdersService.sendBorrowStatus(borrowOrder.getId());
									} else {
										// logger.error("queryRequestPays error 找不到对应的借款记录或者该记录已经被处理过:业务号："
										// + sYURREF);
									}

								} else if (sYURREF.startsWith("B")) {

									List<BorrowOrderLoan> bdls = borrowOrderLoanDao.findParams(params);
									if (bdls != null && bdls.size() > 0) {
										BorrowOrderLoan bdlNew = new BorrowOrderLoan();
										bdlNew.setYurref(sYURREF);
										bdlNew.setPayRemark(payRemark);
										bdlNew.setPayStatus(code);
										bdlNew.setUpdatedAt(nowDate);
										if (code.equals(BorrowOrder.SUB_PAY_SUCC)) {
											bdlNew.setCapitalType(curLoanAccount);
											bdlNew.setStatus(BorrowOrderLoan.FKCG);
											bdlNew.setLoanTime(zhfkDate);
										}
										borrowOrderLoanDao.updateByYurref(bdlNew);
									}
								} else if (sYURREF.startsWith("C")) {
									// 批量处理
									List<BorrowOrderLoanPerson> bdlPersons = borrowOrderLoanPersonDao
											.findParams(params);
									if (bdlPersons != null && bdlPersons.size() > 0) {
										BorrowOrderLoanPerson bdlPersonNew = new BorrowOrderLoanPerson();
										// bdlPersonNew.setId(bdlPerson.getId());
										bdlPersonNew.setYurref(sYURREF);
										bdlPersonNew.setPayRemark(payRemark);
										bdlPersonNew.setPayStatus(code);
										bdlPersonNew.setUpdatedAt(nowDate);
										if (code.equals(BorrowOrder.SUB_PAY_SUCC)) {
											bdlPersonNew.setCapitalType(curLoanAccount);
											bdlPersonNew.setStatus(BorrowOrderLoan.FKCG);
											bdlPersonNew.setLoanTime(zhfkDate);
										}
										borrowOrderLoanPersonDao.updateByYurref(bdlPersonNew);
									}
								} else if (sYURREF.startsWith("H")) {
									BorrowOrder borrowOrder = null;
									borrowOrder = borrowOrderDao.selectByParamTLO(params);
									if (borrowOrder != null
											&& !borrowOrder.getPaystatus().equals(BorrowOrder.SUB_PAY_SUCC)
											&& borrowOrder.getStatus() == BorrowOrder.STATUS_FKZ) {
										BorrowOrder borrowOrderNew = new BorrowOrder();
										borrowOrderNew.setId(borrowOrder.getId());
										borrowOrderNew.setPayRemark(payRemark);
										borrowOrderNew.setUpdatedAt(nowDate);

										if (code.equals(BorrowOrder.SUB_PAY_SUCC)) {
											borrowOrderNew.setPaystatus(code);
											borrowOrderNew.setCapitalType(curLoanAccount);
											borrowOrderNew.setLoanTime(zhfkDate);
											borrowOrderNew.setStatus(BorrowOrder.STATUS_HKZ);
										} else if (code.equals(BorrowOrder.PAY_PAY_FAIL)) {
											borrowOrderNew.setPaystatus(code);
											borrowOrderNew.setStatus(BorrowOrder.STATUS_FKSB);
										}
										borrowOrderDao.updateByPrimaryKeySelectiveTLO(borrowOrderNew);
									}

								}
							}

						}
					}

				}

			}

		} catch (Exception e) {
			logger.error("queryPaysStateNotCmb   errror", e);

		}
		logger.error("queryPaysStateNotCmb  end ");*/
	}
	//TODO-ZSH
	@Override
	public void queryPaysStateCmb() {
	/*	if (!PropertiesUtil.get("CMB_ISRUN").equals("YES")) {
			logger.error("cmb total is close so   queryPaysStateCmb is close");
			return;
		}
		logger.error("queryPaysStateCmb  starting ");
		try {

			int allAccounts[] = BorrowOrder.LOAN_ACCOUNTS;
			for (int curLoanAccount : allAccounts) {// 查询多个ukey的信息
				HashMap<String, String> dFAccountInfo = borrowOrderService.getDFAccountInfo(curLoanAccount);
				if (!dFAccountInfo.get("DF_ISOPEN").equals("1")) {
					logger.error(
							"account:" + curLoanAccount + "=====daifa   is close queryPaysStateCmb is stop 账户代发功能已关闭！");
					break;
				}
				String orderNo = GenerateNo.nextOrdId();
				// // 生成请求报文
				String requestParams = HttpRequestCMBDF.getRequestNTQRYEBPStr(dFAccountInfo);

				String tablelastName = DateUtil.getDateFormat(new Date(), "yyyyMMdd");
				// 插入订单
				OutOrders orders = new OutOrders();
				orders.setOrderNo(orderNo);
				orders.setOrderType(OutOrders.orderType_cmb);
				// orders.setAssetOrderId(borrowOrder.getId());
				orders.setReqParams(requestParams);
				orders.setAddTime(new Date());
				orders.setAct("GetAgentInfo");
				orders.setStatus(OutOrders.STATUS_WAIT);
				orders.setTablelastName(tablelastName);
				outOrdersService.insertByTablelastName(orders);
				String goUrl = dFAccountInfo.get("DF_URL");
				// 连接前置机，发送请求报文，获得返回报文
				String result = HttpRequestCMBDF.sendRequest(requestParams, goUrl);
				// logger.error("resultParams queryPaysStateCmb: 有返回:" + orderNo);
				// 更新订单
				OutOrders ordersNew = new OutOrders();
				ordersNew.setId(orders.getId());
				ordersNew.setOrderNo(orderNo);
				ordersNew.setReturnParams(result);
				ordersNew.setUpdateTime(new Date());
				ordersNew.setStatus(OutOrders.STATUS_SUC);
				ordersNew.setTablelastName(tablelastName);
				outOrdersService.updateByTablelastName(ordersNew);

				String jsonstring = HttpRequestCMBDF.xml2JSON(result);

				JSONObject jsonObj = JSONObject.fromObject(jsonstring);
				Object objj = jsonObj.get("NTQATSQYZ");
				JSONArray arrays = null;
				if (objj instanceof JSONObject) {
					arrays = new JSONArray();
					arrays.add(objj);

				} else if (objj instanceof JSONArray) {

					arrays = jsonObj.getJSONArray("NTQATSQYZ");
				}

				if (arrays != null && arrays.size() > 0) {

					for (int i = 0; i < arrays.size(); i++) {
						JSONObject obj = arrays.getJSONObject(i);

						String sYURREF = obj.getString("YURREF");
						String sREQSTA = obj.getString("REQSTA");
						String sRTNFLG = obj.getString("RTNFLG");

						if (StringUtils.isNotBlank(sYURREF)) {

							ServiceResult serviceResult = getPayCmbresult(obj, sREQSTA, sRTNFLG);// new
							// ServiceResult(BorrowOrder.PAY_ERROR,
							// "未知异常，请稍后重试！");
							String code = serviceResult.getCode();
							String payRemark = serviceResult.getMsg();
							HashMap<String, Object> params = new HashMap<String, Object>();
							params.put("notPayStatus", BorrowOrder.SUB_PAY_SUCC);
							params.put("yurref", sYURREF);
							Date nowDate = new Date();

							String sOPRDAT = null;
							Date zhfkDate = null;// 真正的放款时间
							if (obj.containsKey("OPRDAT")) {
								sOPRDAT = obj.getString("OPRDAT");
								zhfkDate = DateUtil.cmbToDateByString(sOPRDAT);
							}
							if (sYURREF.startsWith("A")) {

								BorrowOrder borrowOrder = null;

								borrowOrder = borrowOrderDao.selectByParam(params);

								if (borrowOrder != null && !borrowOrder.getPaystatus().equals(BorrowOrder.SUB_PAY_SUCC)
										&& borrowOrder.getStatus() == BorrowOrder.STATUS_FKZ) {

									BorrowOrder borrowOrderNew = new BorrowOrder();
									borrowOrderNew.setId(borrowOrder.getId());
									// borrowOrderNew.setPaystatus(paystatus);
									borrowOrderNew.setPayRemark(payRemark);
									borrowOrderNew.setUpdatedAt(nowDate);

									if (code.equals(BorrowOrder.SUB_PAY_SUCC)) {

										borrowOrderNew.setPaystatus(code);
										borrowOrderNew.setLoanTime(zhfkDate);
										borrowOrderNew.setCapitalType(curLoanAccount);
										borrowOrderNew.setStatus(BorrowOrder.STATUS_HKZ);
										borrowOrderNew
												.setLoanEndTime(DateUtil.addDay(zhfkDate, borrowOrder.getLoanTerm()));// 放款时间加上借款期限

										// 放款成功插入还款记录
										borrowOrder.setPaystatus(code);
										borrowOrder.setStatus(BorrowOrder.STATUS_HKZ);
										borrowOrder.setLoanTime(zhfkDate);
										borrowOrder.setLoanEndTime(borrowOrderNew.getLoanEndTime());// 放款时间加上借款期限

										repaymentService.insertByBorrorOrder(borrowOrder);
										// 插入资产信息
										if (curLoanAccount == BorrowOrder.LOAN_ACCOUNT2) {
											borrowOrderService.addBorrowCheckingExt(borrowOrder);
										} else {
											borrowOrderService.addBorrowChecking(borrowOrder);
										}
										// 设置B可打款

										params.clear();
										params.put("assetOrderId", borrowOrder.getId());
										params.put("status", BorrowOrderLoan.CSZT);
										BorrowOrderLoan bdl = borrowOrderLoanDao.selectByParam(params);
										if (bdl != null) {
											BorrowOrderLoan bdlNew = new BorrowOrderLoan();
											bdlNew.setId(bdl.getId());
											bdlNew.setCapitalType(curLoanAccount);// 设置资产归属
											bdlNew.setUpdatedAt(nowDate);
											bdlNew.setStatus(BorrowOrderLoan.DFK);
											bdlNew.setCreatedAt(zhfkDate);
											borrowOrderLoanDao.updateByPrimaryKeySelective(bdlNew);
										}
										// 设置C可打款
										BorrowOrderLoanPerson bdlPerson = borrowOrderLoanPersonDao
												.selectByParam(params);
										BorrowOrderLoanPerson bdlPersonNew = new BorrowOrderLoanPerson();
										if (bdlPerson != null) {
											bdlPersonNew.setId(bdlPerson.getId());
											bdlPersonNew.setCapitalType(curLoanAccount);// 设置资产归属
											bdlPersonNew.setUpdatedAt(nowDate);
											bdlPersonNew.setStatus(BorrowOrderLoan.DFK);
											bdlPersonNew.setCreatedAt(zhfkDate);
											borrowOrderLoanPersonDao.updateByPrimaryKeySelective(bdlPersonNew);
										}
									} else if (code.equals(BorrowOrder.PAY_PAY_FAIL)) {

										borrowOrderNew.setPaystatus(code);
										borrowOrderNew.setStatus(BorrowOrder.STATUS_FKSB);
									}
									borrowOrderDao.updateByPrimaryKeySelective(borrowOrderNew);
								} else {
									// logger.error("queryRequestPays error 找不到对应的借款记录或者该记录已经被处理过:订单号："
									// + sYURREF);
								}

							} else if (sYURREF.startsWith("B")) {
								params.put("status", BorrowOrderLoan.DKZ);
								List<BorrowOrderLoan> bdls = borrowOrderLoanDao.findParams(params);
								if (bdls != null && bdls.size() > 0) {
									BorrowOrderLoan bdlNew = new BorrowOrderLoan();
									bdlNew.setYurref(sYURREF);
									bdlNew.setPayRemark(payRemark);
									bdlNew.setPayStatus(code);
									bdlNew.setUpdatedAt(nowDate);
									if (code.equals(BorrowOrder.SUB_PAY_SUCC)) {
										bdlNew.setStatus(BorrowOrderLoan.FKCG);
										bdlNew.setLoanTime(zhfkDate);
										bdlNew.setCapitalType(curLoanAccount);
									}
									borrowOrderLoanDao.updateByYurref(bdlNew);
								}
							} else if (sYURREF.startsWith("C")) {
								params.put("status", BorrowOrderLoan.DKZ);
								// 批量处理
								List<BorrowOrderLoanPerson> bdlPersons = borrowOrderLoanPersonDao.findParams(params);
								if (bdlPersons != null && bdlPersons.size() > 0) {
									BorrowOrderLoanPerson bdlPersonNew = new BorrowOrderLoanPerson();
									// bdlPersonNew.setId(bdlPerson.getId());
									bdlPersonNew.setYurref(sYURREF);
									bdlPersonNew.setPayRemark(payRemark);
									bdlPersonNew.setPayStatus(code);
									bdlPersonNew.setUpdatedAt(nowDate);
									if (code.equals(BorrowOrder.SUB_PAY_SUCC)) {
										bdlPersonNew.setStatus(BorrowOrderLoan.FKCG);
										bdlPersonNew.setLoanTime(zhfkDate);
										bdlPersonNew.setCapitalType(curLoanAccount);
									}
									borrowOrderLoanPersonDao.updateByYurref(bdlPersonNew);
								}
							} else if (sYURREF.startsWith("H")) {
								BorrowOrder borrowOrder = null;
								borrowOrder = borrowOrderDao.selectByParamTLO(params);
								if (borrowOrder != null && !borrowOrder.getPaystatus().equals(BorrowOrder.SUB_PAY_SUCC)
										&& borrowOrder.getStatus() == BorrowOrder.STATUS_FKZ) {
									BorrowOrder borrowOrderNew = new BorrowOrder();
									borrowOrderNew.setId(borrowOrder.getId());
									borrowOrderNew.setPayRemark(payRemark);
									borrowOrderNew.setUpdatedAt(nowDate);

									if (code.equals(BorrowOrder.SUB_PAY_SUCC)) {
										borrowOrderNew.setCapitalType(curLoanAccount);
										borrowOrderNew.setPaystatus(code);
										borrowOrderNew.setLoanTime(zhfkDate);
										borrowOrderNew.setStatus(BorrowOrder.STATUS_HKZ);

									} else if (code.equals(BorrowOrder.PAY_PAY_FAIL)) {

										borrowOrderNew.setPaystatus(code);
										borrowOrderNew.setStatus(BorrowOrder.STATUS_FKSB);
									}
									borrowOrderDao.updateByPrimaryKeySelectiveTLO(borrowOrderNew);
								}

							}
						}

					}
				}

			}

		} catch (Exception e) {
			logger.error("queryPaysStateCmb   errror", e);

		}
		logger.error("queryPaysStateCmb  end ");*/
	}

	/**
	 * 计算支付结果 非招行
	 * 
	 * @param obj
	 * @param sREQSTS
	 * @param sRTNFLG
	 * @return
	 */
	//TODO-ZSH
/*	private ServiceResult getPayNotCmbresult(JSONObject obj, String sREQSTS, String sRTNFLG) {

		ServiceResult serviceResult = new ServiceResult(BorrowOrder.PAY_ERROR, "getPayNotCmbresult未知异常，请稍后重试！");
		try {

			if (sREQSTS.equals("FIN") && sRTNFLG.equals("F")) {
				serviceResult = new ServiceResult(BorrowOrder.PAY_PAY_FAIL, "支付失败");

			} else if (sREQSTS.equals("FIN") && sRTNFLG.equals("S")) {

				serviceResult = new ServiceResult(BorrowOrder.SUB_PAY_SUCC, "支付成功");

			} else {
				serviceResult = new ServiceResult(BorrowOrder.PAY_SUBMIT, "支付已被银行受理（支付状态：" + sREQSTS + "）");

			}
		} catch (Exception e) {
			logger.error("getPayNotCmbresult error", e);
		}
		return serviceResult;
	}*/

	/**
	 * 计算支付结果 招行
	 * 
	 * @param propPayResult
	 * @param sREQSTS
	 * @param sRTNFLG
	 * @return
	 */
	//TODO-ZSH
/*	private ServiceResult getPayCmbresult(JSONObject propPayResult, String sREQSTS, String sRTNFLG) {

		ServiceResult serviceResult = new ServiceResult(BorrowOrder.PAY_ERROR, "getPayCmbresult未知异常，请稍后重试！");
		try {
			if (sREQSTS.equals("FIN") && sRTNFLG.equals("F")) {

				serviceResult = new ServiceResult(BorrowOrder.SUB_PAY_FAIL, "银行支付失败");

			} else if (sREQSTS.equals("FIN") && sRTNFLG.equals("S")) {
				serviceResult.setCode(BorrowOrder.SUB_PAY_SUCC);
				serviceResult.setMsg("银行支付成功");

			} else {
				serviceResult = new ServiceResult(BorrowOrder.PAY_SUBMIT, "支付已被银行受理（支付状态：" + sREQSTS + "）");

			}

			if (propPayResult.containsKey("ERRDSP")) {
				serviceResult.setMsg(serviceResult.getMsg() + propPayResult.getString("ERRDSP"));
			}
		} catch (Exception e) {
			logger.error("getPayCmbresult error", e);
		}

		return serviceResult;

	}*/

	public void payLoanInterestPays() {
		payLoanInterestPays(null);
	}

	@Override
	public void payLoanInterestPays(String loanType) {
	/*	Date nowDate = new Date();
		int nowHour = nowDate.getHours();
		int monutes = nowDate.getMinutes();
		// 避免交替日打款错误，23点55到第二天0点05分期间，不打款
		if (nowHour == 23) {
			if (monutes > 55) {
				return;
			}

		}

		if (nowHour == 0) {
			if (monutes < 5) {
				return;
			}

		}
		if (loanType == null) {
			LinkedHashMap<String, String> mapFee = SysCacheUtils.getConfigParams(BackConfigParams.FEE_ACCOUNT);
			String companyFeeIsopen = mapFee.get("company_fee_isopen");
			String personFeeIsopen = mapFee.get("person_fee_isopen");
			if (companyFeeIsopen.equals("1")) {
				updatePayLoanInterestPaysB();
			}
			if (personFeeIsopen.equals("1")) {
				updatePayLoanInterestPaysC();
			}
		} else if (loanType.equals("loanB")) {
			updatePayLoanInterestPaysB();
		} else if (loanType.equals("loanC")) {
			updatePayLoanInterestPaysC();
		}*/

	}
	//TODO-ZSH
	/**
	 * 利全公司服务费打款
	 */
	public void updatePayLoanInterestPaysB() {

	/*	try {
			LinkedHashMap<String, String> mapFee = SysCacheUtils.getConfigParams(BackConfigParams.FEE_ACCOUNT);
			// 打款B
			String cardNoB = mapFee.get("cardNoB");// "1001171609200156829";//
			// 銀行卡号
			String cardNumberB = mapFee.get("cardNumberB");// "102100099996";//
			// 银行号
			String userPhoneB = mapFee.get("userPhoneB");// "13918201587";// 手机号
			String realNameB = mapFee.get("realNameB");// "上海利全信息科技服务有限公司";// 姓名
			Integer isCmbB = Integer.parseInt(mapFee.get("isCmbB"));// 2;// 是否招行

			Integer intoMoneyB = 0;// 打款金额单位分
			List<Integer> listIdB = new ArrayList<Integer>();
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("status", BorrowOrderLoan.DFK);
			params.put("payStatus", BorrowOrder.SUB_PAY_CSZT);
			params.put("islistPage", "yes");
			params.put("querylimit", 400);
			// 查询出所有待打款的记录
			List<BorrowOrderLoan> bdls = borrowOrderLoanDao.findParams(params);

			if (bdls != null && bdls.size() > 0) {
				for (BorrowOrderLoan bdl : bdls) {
					intoMoneyB += bdl.getLoanInterests();
					listIdB.add(bdl.getId());
				}

				if (intoMoneyB > 0) {
					String orderNoB = GenerateNo.payRecordNo("B");
					List<BorrowOrder> bos = new ArrayList<BorrowOrder>();
					BorrowOrder bo = new BorrowOrder();
					bo.setYurref(orderNoB);
					bo.setUserPhone(userPhoneB);
					bo.setCardNo(cardNoB);
					bo.setRealname(realNameB);
					bo.setBankNumber(cardNumberB);
					bo.setIntoMoney(intoMoneyB);
					bos.add(bo);
					ServiceResult serviceResult = null;
					if (isCmbB == 2) {// 非招商
						serviceResult = borrowOrderService.subPayNotCmb(bos, OutOrders.act_NTQRYEBP_B);
						String paystatus = serviceResult.getCode();
						if (paystatus.equals("5000")) {// 返回每个订单的结果
							List<ServiceResult> resultS = (List<ServiceResult>) serviceResult.getExt();
							if (resultS != null && resultS.size() > 0) {
								serviceResult = new ServiceResult(resultS.get(0).getCode(), resultS.get(0).getMsg());
							}
						}
						logger.error("result  Loan " + OutOrders.act_NTQRYEBP_B + "，订单号：" + orderNoB + "==="
								+ serviceResult.getCode() + ">>" + serviceResult.getMsg());
					} else if (isCmbB == 1) {// 招行
						serviceResult = borrowOrderService.subPayCmb(bos, OutOrders.act_AgentRequest_B);
						logger.error("result  Loan " + OutOrders.act_AgentRequest_B + "，订单号：" + orderNoB + "==="
								+ serviceResult.getCode() + ">>" + serviceResult.getMsg());

					}
					if (serviceResult != null) {
						String paystatus = serviceResult.getCode();
						String payRemark = serviceResult.getMsg();
						HashMap<String, Object> paramsUpdate = new HashMap<String, Object>();
						Date fkDate = new Date();
						paramsUpdate.put("ids", listIdB);
						paramsUpdate.put("yurref", orderNoB);
						paramsUpdate.put("payRemark", payRemark);
						// 网络失败不改变付款状态，自动重新打款
						if (!paystatus.equals(BorrowOrder.SUB_NERWORK_ERROR)) {
							paramsUpdate.put("payStatus", paystatus);
						}

						paramsUpdate.put("updatedAt", fkDate);
						if (paystatus.equals(BorrowOrder.SUB_SUBMIT)) {
							paramsUpdate.put("status", BorrowOrderLoan.DKZ);
							logger.error("updatePayLoanInterestPaysB  submit success  公司服务费打款提交成功！");
						}
						borrowOrderLoanDao.updateByParams(paramsUpdate);
					}

				}

			}
		} catch (Exception e) {
			logger.error("NTQRYEBP Loan B error");
			e.printStackTrace();
		}*/

	}

	/**
	 * 利全个人服务费打款
	 * 
	 */
	
	//TODO-ZSH
	public void updatePayLoanInterestPaysC() {

	/*	try {

			// 打款C
			// String cardNoC = "6225882140980282";// 銀行卡号
			// String cardNumberC = "308584000013";// 银行号
			// String userPhoneC = "18817322995";// 手机号
			// String realNameC = "林杰";// 姓名
			// Integer isCmbC = 1;// 是否招行
			//
			LinkedHashMap<String, String> mapFee = SysCacheUtils.getConfigParams(BackConfigParams.FEE_ACCOUNT);
			String cardNoC = mapFee.get("cardNoC");// "1001171609200156829";//
			// 銀行卡号
			String cardNumberC = mapFee.get("cardNumberC");// "102100099996";//
			// 银行号
			String userPhoneC = mapFee.get("userPhoneC");// "13918201587";// 手机号
			String realNameC = mapFee.get("realNameC");// "上海利全信息科技服务有限公司";// 姓名
			Integer isCmbC = Integer.parseInt(mapFee.get("isCmbC"));// 2;// 是否招行

			Integer intoMoneyC = 0;// 打款金额单位分

			//
			// Integer intoMoneyB = 0;// 打款金额单位分
			List<Integer> listIdC = new ArrayList<Integer>();
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("status", BorrowOrderLoan.DFK);
			params.put("payStatus", BorrowOrder.SUB_PAY_CSZT);
			params.put("islistPage", "yes");
			params.put("querylimit", 200);
			// 查询出所有待打款的记录
			List<BorrowOrderLoanPerson> bdlPersons = borrowOrderLoanPersonDao.findParams(params);

			if (bdlPersons != null && bdlPersons.size() > 0) {
				for (BorrowOrderLoanPerson bdl : bdlPersons) {
					intoMoneyC += bdl.getLoanInterests();
					listIdC.add(bdl.getId());
				}

				if (intoMoneyC > 0) {

					String orderNoC = GenerateNo.payRecordNo("C");
					List<BorrowOrder> bos = new ArrayList<BorrowOrder>();
					BorrowOrder bo = new BorrowOrder();
					bo.setYurref(orderNoC);
					bo.setUserPhone(userPhoneC);
					bo.setCardNo(cardNoC);
					bo.setRealname(realNameC);
					bo.setBankNumber(cardNumberC);
					bo.setIntoMoney(intoMoneyC);
					bos.add(bo);
					ServiceResult serviceResult = null;
					if (isCmbC == 1) {// 招行
						serviceResult = borrowOrderService.subPayCmb(bos, OutOrders.act_AgentRequest_C);
						logger.error("result  Loan " + OutOrders.act_AgentRequest_C + "，订单号：" + orderNoC + "==="
								+ serviceResult.getCode() + ">>" + serviceResult.getMsg());
					} else if (isCmbC == 2) {// 非招行
						serviceResult = borrowOrderService.subPayNotCmb(bos, OutOrders.act_NTQRYEBP_C);
						String paystatus = serviceResult.getCode();
						if (paystatus.equals("5000")) {// 返回每个订单的结果
							List<ServiceResult> resultS = (List<ServiceResult>) serviceResult.getExt();
							if (resultS != null && resultS.size() > 0) {
								serviceResult = new ServiceResult(resultS.get(0).getCode(), resultS.get(0).getMsg());
							}
						}
						logger.error("result  Loan " + OutOrders.act_NTQRYEBP_C + "，订单号：" + orderNoC + "==="
								+ serviceResult.getCode() + ">>" + serviceResult.getMsg());
					}

					if (serviceResult != null) {

						String paystatus = serviceResult.getCode();
						String payRemark = serviceResult.getMsg();

						HashMap<String, Object> paramsUpdate = new HashMap<String, Object>();
						Date fkDate = new Date();
						paramsUpdate.put("ids", listIdC);
						paramsUpdate.put("yurref", orderNoC);
						paramsUpdate.put("payRemark", payRemark);
						// 网络失败不改变付款状态，自动重新打款
						if (!paystatus.equals(BorrowOrder.SUB_NERWORK_ERROR)) {
							paramsUpdate.put("payStatus", paystatus);
						}
						paramsUpdate.put("updatedAt", fkDate);
						if (paystatus.equals(BorrowOrder.SUB_SUBMIT)) {
							paramsUpdate.put("status", BorrowOrderLoan.DKZ);
							logger.error("updatePayLoanInterestPaysC  submit success  个人服务费打款提交成功！");
						}
						// if (paystatus.equals(BorrowOrder.SUB_PAY_SUCC)) {
						// paramsUpdate.put("status", BorrowOrderLoan.FKCG);
						// paramsUpdate.put("loanTime", fkDate);
						// }
						borrowOrderLoanPersonDao.updateByParams(paramsUpdate);

					}
				}

			}

		} catch (Exception e) {
			logger.error("updatePayLoanInterestPaysC Loan C error");
			e.printStackTrace();
		}*/
	}

	@Override
	public void updateLoanTerm() {
/*		Date nowDate = new Date();
		int nowHour = nowDate.getHours();
		int monutes = nowDate.getMinutes();
		// 避免交替日打款错误，23点55到第二天0点05分期间，不打款
		if (nowHour == 23) {
			if (monutes > 55) {
				return;
			}

		}

		if (nowHour == 0) {
			if (monutes < 5) {
				return;
			}

		}

		LinkedHashMap<String, String> mapApi = SysCacheUtils.getConfigParams(BackConfigParams.YANGYUE_MDL_API);
		String userFeeIsopen = mapApi.get(BackConfigParams.MDL_API_ISOPEN);
		String assetSize = mapApi.get(BackConfigParams.MDL_ASSET_SIZE);

		if (!userFeeIsopen.equals("1")) {
			logger.error("CMB  loan_user is  close P2P打款已关闭！");
			return;
		}
		logger.error("begin   updateLoanTerm  ======");
		// 非招行打款
		HashMap<String, Object> paramsM = new HashMap<String, Object>();
		paramsM.put("borrowStatus", BorrowOrder.STATUS_FKZ);
		paramsM.put("payStatus", BorrowOrder.SUB_PAY_CSZT);
		paramsM.put("queryType", "subPay");
		try {
			int loanTerms[] = BorrowOrder.LOAN_TREMS;

			try {

				for (int loanTerm : loanTerms) {
					paramsM.put("bankIscmb", 2);
					paramsM.put("loanTerm", loanTerm);
					paramsM.put("querylimit", Integer.valueOf(assetSize));
					List<BorrowOrder> bos = borrowOrderService.findAll(paramsM);
					if (bos != null && bos.size() > 0) {

						logger.error("begin   Loan  ======" + OutOrders.act_NTQRYEBP_A);

						borrowOrderService.requestPaysNotCmbUser(bos, loanTerm);

						logger.error("end   Loan  ======" + OutOrders.act_NTQRYEBP_A);
					}
					// Thread.sleep(1000);
					// 查询非招行状态

				}
				// queryPaysStateNotCmb();
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("error   Loan  ======" + OutOrders.act_NTQRYEBP_A + e.getMessage());
			}

		} catch (Exception e) {
			logger.error("updateLoanTerm error", e);
		}
		logger.error("end   updateLoanTerm  ======");*/

	}

	@Override
	public void channelReport() {

		/*try {

			Calendar cal = Calendar.getInstance();
			Integer checkDate = 0;
			String time = DateUtil.getDateFormat(cal.getTime(), "yyyy-MM-dd HH:mm:ss");
			checkDate = Integer.valueOf(time.substring(11, 13));
			logger.error("地推统计 开始-------------->thirdChannelReport start time--->" + time);
			if (checkDate > 1 && checkDate < 6) {

				final String nowDate = DateUtil.getDateFormat(cal.getTime(), "yyyy-MM-dd");

				try {

					ThreadPool4.getInstance().run(new Runnable() {
						@Override
						public void run() {

							thirdChannelReportService.saveThirdChannelReport(nowDate);
						}
					});
				} catch (Exception e) {
					logger.error("thirdChannelReport  thread error", e);
				}

				// if (checkDate == 2) {
				// logger.error("liangdianle begin begin fuwufeu Thread");
				// ThreadPool3.getInstance().run(new Runnable() {
				// @Override
				// public void run() {
				// updateThreeLoanTerm();
				// }
				// });
				//
				// }

			}
			logger.error("地推统计 结束-------------->loanReport end");
		} catch (Exception e) {
			logger.error("thirdChannelReportTaskJob error", e);
		}

		logger.error("每日放款统计 开始-------------->loanReport start");
		try {
			final String nowTime = null;

			ThreadPool4.getInstance().run(new Runnable() {
				@Override
				public void run() {
					loanReportService.saveLoanReport(nowTime);
				}
			});

		} catch (Exception e) {
			logger.error("loanReportTaskJob error", e);
		}
		logger.error("每日放款统计 结束-------------->loanReport end");
		logger.error("地推统计 开始-------------->thirdChannelReport start");
		logger.error("推广统计 开始-------------->channelReport start");
		try {
			final String nowTime = null;
			ThreadPool4.getInstance().run(new Runnable() {
				@Override
				public void run() {
					channelReportService.saveChannelReport(nowTime);
				}
			});

		} catch (Exception e) {
			logger.error("channelReportTaskJob error", e);
		}
		logger.error("推广统计 结束-------------->channelReport end");*/
	}

	@Override
	public void thirdReport() {
		/*try {
			Calendar cal = Calendar.getInstance();
			cal.add(Calendar.DATE, -1);
			String nowTime = DateUtil.getDateFormat(cal.getTime(), "yyyy-MM-dd");
			logger.error("thirdChannelReport pushreport start ---------------" + nowTime);
			thirdChannelReportService.pushUserReport(nowTime);
			logger.error("thirdChannelReport pushreport end ---------------" + nowTime);
		} catch (Exception e) {
			logger.error("thirdChannelReport error", e);
		}

		try {
			Calendar cal = Calendar.getInstance();
			cal.add(Calendar.DATE, -1);
			String nowTime = DateUtil.getDateFormat(cal.getTime(), "yyyy-MM-dd");
			logger.error("saveLoanMoneyReport start ---------------" + nowTime);
			loanMoneyReportService.saveLoanMoneyReport(nowTime);
			logger.error("saveLoanMoneyReport end ---------------" + nowTime);
		} catch (Exception e) {
			logger.error("saveLoanMoneyReport error", e);
		}*/
	}

	@Override
	public void insertReport() {
		/*logger.error("insertReport is running");
		Calendar now = Calendar.getInstance();
		now.add(Calendar.DAY_OF_YEAR, -1);
		backStatisticService.updateReport(now, now);

		try {
			logger.error("thirdChannelReport pushreport start ---------------");
			String nowTime = DateUtil.getDateFormat(now.getTime(), "yyyy-MM-dd");
			thirdChannelReportService.pushUserReport(nowTime);
			logger.error("thirdChannelReport pushreport end ---------------");
		} catch (Exception e) {
			logger.error("thirdChannelReport error", e);
		}*/
	}

	@Override
	public void assetsDivision() {
	/*	try {
			logger.error("info  assetsDivision begin-----");
			LinkedHashMap<String, String> ASSETS_TYPE = SysCacheUtils.getConfigParams("ASSETS_TYPE");
			Integer ASSEST_CURRENT = Integer.parseInt(ASSETS_TYPE.get("ASSEST_CURRENT"));

			HashMap<String, Object> params = new HashMap<String, Object>();
			// 口袋
			params.put("sysType", "ASSEST_KD");
			List<BackConfigParams> listASSEST_KD = backConfigParamsService.findParams(params);
			BackConfigParams avaiMoneny_kdvo = null;
			BackConfigParams update_kdvo = null;
			Long kdAvaiMoney = 0L;
			for (BackConfigParams kd : listASSEST_KD) {
				if (kd.getSysKey().equals("ASSEST_AVAIMONEY_KD")) {
					avaiMoneny_kdvo = kd;
					kdAvaiMoney = Long.valueOf((kd.getSysValue())) * 100;
				}
				if (kd.getSysKey().equals("ASSEST_UPDATETIME_KD")) {
					update_kdvo = kd;
				}
			}
			// 温州贷
			params.put("sysType", "ASSEST_WZD");
			List<BackConfigParams> listASSEST_WZD = backConfigParamsService.findParams(params);
			BackConfigParams avaiMoneny_wzdvo = null;
			BackConfigParams update_wzdvo = null;
			Long wzdAvaiMoney = 0L;
			for (BackConfigParams kd : listASSEST_WZD) {
				if (kd.getSysKey().equals("ASSEST_AVAIMONEY_WZD")) {
					avaiMoneny_wzdvo = kd;
					wzdAvaiMoney = Long.valueOf((kd.getSysValue())) * 100;
				}
				if (kd.getSysKey().equals("ASSEST_UPDATETIME_WZD")) {
					update_wzdvo = kd;
				}
			}

			if (ASSEST_CURRENT == BorrowOrderChecking.ASSEST_LQ) {

			} else {
				params.clear();
				params.put("capitalType", BorrowOrderChecking.ASSEST_LQ);
				params.put("islistPage", "yes");
				params.put("queryType", "subPay");
				params.put("noStatus", BorrowOrderChecking.STATUS_TSCG);
				params.put("querylimit", 500);
				List<BorrowOrderChecking> lists = borrowOrderCheckingDao.selectAll(params);

				if (lists != null && lists.size() > 0) {
					if (kdAvaiMoney > 0 || wzdAvaiMoney > 0) {// 口袋或者温州贷可用资产大于0
						for (BorrowOrderChecking bo : lists) {
							BorrowOrderChecking newBo = new BorrowOrderChecking();
							newBo.setId(bo.getId());
							if (kdAvaiMoney > 0 || wzdAvaiMoney > 0) {// 口袋或者温州贷可用资产大于0

								// 判断当前记录所说资方
								if (ASSEST_CURRENT == BorrowOrderChecking.ASSEST_KD) {// 1口袋
									if (kdAvaiMoney > 0) {
									} else if (wzdAvaiMoney > 0) {
										ASSEST_CURRENT = BorrowOrderChecking.ASSEST_WZD;
									} else {
										ASSEST_CURRENT = BorrowOrderChecking.ASSEST_LQ;
									}
								} else if (ASSEST_CURRENT == BorrowOrderChecking.ASSEST_WZD) {// 温州贷
									if (wzdAvaiMoney > 0) {
									} else if (kdAvaiMoney > 0) {
										ASSEST_CURRENT = BorrowOrderChecking.ASSEST_KD;
									} else {
										ASSEST_CURRENT = BorrowOrderChecking.ASSEST_LQ;
									}
								}

								// 根据所属资方进行操作
								if (ASSEST_CURRENT == BorrowOrderChecking.ASSEST_LQ) {
									break;
								} else if (ASSEST_CURRENT == BorrowOrderChecking.ASSEST_KD) {
									// kdAvaiMoney -= bo.getMoneyAmount();
									ServiceResult result = borrowOrderService.addDocking(bo);
									newBo.setRemark(result.getMsg());
									newBo.setStatus(Integer.parseInt(result.getCode()));
									if (result.getExt() != null) {
										newBo.setOutNo(String.valueOf(result.getExt()));
									}
								} else if (ASSEST_CURRENT == BorrowOrderChecking.ASSEST_WZD) {
									// wzdAvaiMoney -= bo.getMoneyAmount();
								}
								newBo.setCapitalType(ASSEST_CURRENT);
								newBo.setUpdatedAt(new Date());
								borrowOrderCheckingDao.updateByPrimaryKeySelective(newBo);
							}
						}
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						// 更新资产金额
						List<BackConfigParams> list = new ArrayList<BackConfigParams>();
						avaiMoneny_kdvo.setSysValue(String.valueOf(kdAvaiMoney / 100));
						avaiMoneny_wzdvo.setSysValue(String.valueOf(wzdAvaiMoney / 100));
						update_kdvo.setSysValue(sdf.format(new Date()));
						update_wzdvo.setSysValue(sdf.format(new Date()));
						list.add(avaiMoneny_kdvo);
						list.add(avaiMoneny_wzdvo);
						list.add(update_kdvo);
						list.add(update_wzdvo);
						backConfigParamsService.updateValue(list, null);
					}

				} else {
					logger.error(" info no   assesst to  share......");
				}

				try {
					// 补发口袋未成功的单子
					reSendKDDocking();
				} catch (Exception e) {
					logger.error("reSendKDDocking error");
				}

			}

			logger.error("info  assetsDivision end-----");
		} catch (Exception e) {
			logger.error("error assetsDivision error......", e);
		}

		*//**
		 * 预警短信提醒后台人员
		 *//*
		try {
			sendAlarmMsg();
		} catch (Exception e) {
			logger.error("sendAlarmMsg   error ==== ", e);
		}*/
	}

	/**
	 * 口袋资产推送
	 */
	//TODO-ZSH
	@Override
	public void reSendKDDocking() {
	/*	try {
			// 补发失败的单子
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("capitalType", BorrowOrderChecking.ASSEST_KD);
			params.put("notStatus", BorrowOrderChecking.STATUS_TSCG);
			params.put("islistPage", "yes");
			params.put("queryType", "subPay");
			params.put("idNumberFalg", "yes");
			params.put("querylimit", 1000);
			List<BorrowOrderChecking> listserror = borrowOrderCheckingDao.selectAll(params);
			if (listserror != null && listserror.size() > 0) {
				logger.error("begin reSendKDDocking*****");
				for (BorrowOrderChecking eo : listserror) {
					BorrowOrderChecking newBo = new BorrowOrderChecking();
					newBo.setId(eo.getId());
					ServiceResult result = borrowOrderService.addDocking(eo);
					newBo.setRemark(result.getMsg());
					newBo.setStatus(Integer.parseInt(result.getCode()));
					if (result.getExt() != null) {
						newBo.setOutNo(String.valueOf(result.getExt()));
					}
					borrowOrderCheckingDao.updateByPrimaryKeySelective(newBo);
				}
			}
		} catch (Exception e) {
			logger.error("reSendKDDocking error", e);
		}*/
	}

	/**
	 * 招财猫资产补推送
	 */
	@Override
	public void reSendKDDockingExt() {

	}

	@Override
	public void assetsDivisionExt() {
	/*	try {
			logger.error("info  assetsDivisionExt begin-----");

			HashMap<String, Object> params = new HashMap<String, Object>();
			Date nowDate = new Date();
			borrowOrderService.assetpackqueryZCM(null);

			int loanTerms[] = BorrowOrder.LOAN_TREMS;// 循环推送7天14天
			for (int loanTerm : loanTerms) {
				params.clear();
				logger.error("begin assetsDivisionExt loanTerm:" + loanTerm);
				params.put("borrowCycle", loanTerm);
				params.put("packetTime", DateUtil.getDateFormat(nowDate, "yyyy-MM-dd"));
				params.put("fillupFlag", 0);
				BorrowAssetPacket bap = borrowAssetPacketDao.selectByParam(params);
				if (bap != null) {
					params.clear();
					params.put("signStatus", 0);// 没有被标记
					params.put("loanTime", DateUtil.getDateFormat(nowDate, "yyyy-MM-dd"));
					params.put("capitalType", 0);// 没有被标记资产方
					params.put("loanTerm", loanTerm);
					params.put("noStatus", 2);
					List<BorrowOrderCheckingExt> boceList = borrowOrderCheckingExtDao.findParams(params);
					if (boceList != null && boceList.size() > 0) {
						for (BorrowOrderCheckingExt bo : boceList) {
							bo.setPacketId(bap.getId());
							ServiceResult serviceResult = borrowOrderService.addDockingExtZCM(bo);
							if (serviceResult.getCode().equals("501000")) {
								logger.error("501000 time：" + bap.getPacketTime() + "====type：" + bap.getBorrowCycle()
										+ "== fullsuccess");
								break;
							}
						}
					}

				} else {
					logger.error("ZCM no data to send  ==========time：" + nowDate + ",loanTerm:" + loanTerm);
				}
			}

			logger.error("info  assetsDivisionExt end-----");
		} catch (Exception e) {
			logger.error("error assetsDivisionExt error......", e);
		}*/

	}

	public void sendAlarmMsg() {
		logger.error("begin judge sendAlarmMsg=====");
		try {

			Thread t = new Thread(new Runnable() {
				@Override
				public void run() {

					loaningCountAlarm();
					jsTgvAlarm();
					djsCountAlarm();

				}
			});
			t.start();
		} catch (Exception e) {
			logger.error("sendAlarmMsg error 预警提醒  错误！", e);
		}

	}

	/**
	 * 打款中订单每天累计5次超过500单，发送提醒
	 */
	public void loaningCountAlarm() {
		try {

			String keyloaning = "keyloaning";
			String keyalarmFlag = "keyalarmFlag";
			Boolean loaningFlag = true;// 是否发送短信
			int loaningAlarmSum = 0;// 统计次数
			int alarmCount = 500;// 判断限制
			if (jedisCluster.get(keyloaning) != null) {
				loaningAlarmSum = Integer.parseInt(jedisCluster.get(keyloaning));
				loaningFlag = Boolean.parseBoolean(jedisCluster.get(keyalarmFlag));
			} else {
				jedisCluster.setex(keyloaning, BorrowOrder.ALARM_ONEDAY, "0");
				jedisCluster.setex(keyalarmFlag, BorrowOrder.ALARM_ONEDAY, "true");
			}

			if (loaningFlag) {
				// 放款中笔数超过多少5次发短信
				Map<String, Object> map = sendMoneyStatisticDao.findLoaning();
				if (map != null && map.size() > 0) {
					int loaningCount = Integer.parseInt(String.valueOf(map.get("loaningCount")));
					if (loaningCount > alarmCount) {
						loaningAlarmSum += 1;
						jedisCluster.set(keyloaning, String.valueOf(loaningAlarmSum));
					}
					if (loaningAlarmSum > 4 && loaningFlag) {
						loaningFlag = false;
						jedisCluster.set(keyloaning, "0");
						jedisCluster.set(keyalarmFlag, "false");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"当前放款中订单超过：" + alarmCount + "单,请相关人员及时确认，确认后记得重新打开提醒功能！");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"陈总，您好！当前放款中订单超过：" + alarmCount + "单,请相关人员及时确认，确认后记得重新打开提醒功能！");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"蔡总，您好！当前放款中订单超过：" + alarmCount + "单,请相关人员及时确认，确认后记得重新打开提醒功能！");

						logger.error("已发送放款中提醒短信");
						logger.error(" alarm  alarm  loaning order  借款订单超过500需要核实处理.......zjb");
					}
				}
			}
		} catch (Exception e) {
			logger.error("loaningCountAlarm error ", e);
		}
	}

	/**
	 * 机审通过率每天累计5次超过30%，发送提醒
	 */
	public void jsTgvAlarm() {
		try {

			String keyJsTgv = "keyJsTgv";
			String keyJsTgvalarmFlag = "keyJsTgvFlag";
			Boolean jsTgvFlag = true;// 是否发送短信
			int loaningAlarmSum = 0;// 统计次数
			BigDecimal alarmCount = new BigDecimal(30);// 判断限制
			if (jedisCluster.get(keyJsTgv) != null) {
				loaningAlarmSum = Integer.parseInt(jedisCluster.get(keyJsTgv));
				jsTgvFlag = Boolean.parseBoolean(jedisCluster.get(keyJsTgvalarmFlag));
			} else {
				jedisCluster.setex(keyJsTgv, BorrowOrder.ALARM_ONEDAY, "0");
				jedisCluster.setex(keyJsTgvalarmFlag, BorrowOrder.ALARM_ONEDAY, "true");
			}

			if (jsTgvFlag) {

				Map<String, Object> params = new HashMap<String, Object>();
				List<Integer> list1 = sendMoneyStatisticDao.findRiskOrdersToday();
				if (list1 != null && list1.size() > 0) {

					Integer riskOrdersTotalToday = list1.get(0);
					Integer riskOrdersPassToday = list1.get(1);
					BigDecimal riskOrdersPassRateToday = BigDecimal.ZERO;
					if (riskOrdersTotalToday != null && riskOrdersTotalToday.intValue() != 0) {
						riskOrdersPassRateToday = new BigDecimal(riskOrdersPassToday).multiply(new BigDecimal(100))
								.divide(new BigDecimal(riskOrdersTotalToday), 2, BigDecimal.ROUND_HALF_UP);
					}

					if (riskOrdersPassRateToday.compareTo(alarmCount) == 1) {
						loaningAlarmSum += 1;
						jedisCluster.set(keyJsTgv, String.valueOf(loaningAlarmSum));
					}
					if (loaningAlarmSum > 4 && jsTgvFlag) {
						jsTgvFlag = false;
						jedisCluster.set(keyJsTgv, "0");
						jedisCluster.set(keyJsTgvalarmFlag, "false");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"当前机审通过率超过：" + alarmCount + "%,请相关人员尽快查看确认，确认后记得重新打开提醒功能！");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"陈总，您好！当前机审通过率超过：" + alarmCount + "%,请相关人员尽快查看确认，确认后记得重新打开提醒功能！");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"蔡总，您好！当前机审通过率超过：" + alarmCount + "%,请相关人员尽快查看确认，确认后记得重新打开提醒功能！");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"当前机审通过率超过：" + alarmCount + "%,请相关人员尽快查看确认，确认后记得重新打开提醒功能！");

						logger.error("已发送机审通过率提醒短信");
						logger.error("   alarm  jsTgvAlarm    当前机审通过率超过30%需要核实处理.......fyc");
					}
				}
			}
		} catch (Exception e) {
			logger.error("jsTgvAlarm error ", e);
		}
	}

	/**
	 * 待机审订单每天累计5次超过500单，发送提醒
	 */
	public void djsCountAlarm() {
		try {

			String keyloaning = "keyDjsCount";
			String keyalarmFlag = "keyDjsCountFlag";
			Boolean loaningFlag = true;// 是否发送短信
			int loaningAlarmSum = 0;// 统计次数
			int alarmCount = 500;// 判断限制
			if (jedisCluster.get(keyloaning) != null) {
				loaningAlarmSum = Integer.parseInt(jedisCluster.get(keyloaning));
				loaningFlag = Boolean.parseBoolean(jedisCluster.get(keyalarmFlag));
			} else {
				jedisCluster.setex(keyloaning, BorrowOrder.ALARM_ONEDAY, "0");
				jedisCluster.setex(keyalarmFlag, BorrowOrder.ALARM_ONEDAY, "true");
			}

			if (loaningFlag) {
				// 放款中笔数超过多少5次发短信
				List<Integer> list1 = sendMoneyStatisticDao.findDjsOrdersToday();
				if (list1 != null && list1.size() > 0) {
					int loaningCount = list1.get(0);
					;
					if (loaningCount > alarmCount) {
						loaningAlarmSum += 1;
						jedisCluster.set(keyloaning, String.valueOf(loaningAlarmSum));
					}
					if (loaningAlarmSum > 4 && loaningFlag) {
						loaningFlag = false;
						jedisCluster.set(keyloaning, "0");
						jedisCluster.set(keyalarmFlag, "false");

						SendSmsUtil.sendSmsDiyCL("13817876783",
								"当前待机审订单超过：" + alarmCount + "单,请相关人员尽快查看确认，确认后记得重新打开提醒功能！");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"陈总，您好！当前待机审订单超过：" + alarmCount + "单,请相关人员尽快查看确认，确认后记得重新打开提醒功能！");
						SendSmsUtil.sendSmsDiyCL("13817876783",
								"蔡总，您好！当前待机审订单超过：" + alarmCount + "单,请相关人员尽快查看确认，确认后记得重新打开提醒功能！");
						logger.error("已发送djsCountAlarm提醒短信");
					}
				}
			} else {
				logger.error(" djsCountAlarm   待机审订单当天累计5次超过500单，发送提醒.......fyc");
			}
		} catch (Exception e) {
			logger.error("djsCountAlarm error", e);
		}
	}

	@Override
	public void restartAlarm() {
		String keyJsTgv = "keyJsTgv";
		String keyJsTgvalarmFlag = "keyJsTgvFlag";

		String keyloaning = "keyloaning";
		String keyalarmFlag = "keyalarmFlag";

		String jsCount = "keyDjsCount";
		String keyDjsalarmFlag = "keyDjsCountFlag";

		jedisCluster.set(keyJsTgv, "0");
		jedisCluster.set(keyloaning, "0");
		jedisCluster.set(jsCount, "0");

		jedisCluster.set(keyJsTgvalarmFlag, "true");
		jedisCluster.set(keyalarmFlag, "true");
		jedisCluster.set(keyDjsalarmFlag, "true");

	}

	@Override
	public void createBorrowStaticsReport() {
		try {
			borrowStatisticsReportService.createborrowStaticReportDateByDate(null);
		} catch (Exception e) {
			logger.error("createBorrowStaticsReport error", e);
		}

	}

	@Override
	public void updateThreeLoanTerm() {
//		logger.error("begin updateThreeLoanTerm**********");
//
//		LinkedHashMap<String, String> mapFee = SysCacheUtils.getConfigParams(BackConfigParams.FEE_ACCOUNT);
//		String jujiusongIsopen = mapFee.get("jujiusong_isopen");
//		if (PropertiesUtil.get("CMB_ISRUN").equals("YES") || jujiusongIsopen.equals("1")) {
//			threeLoanOrderService.updateThreeLoanTerm(null);
//		}
//
//		logger.error("end updateThreeLoanTerm**********");
	}
	//TODO-ZSH
	@Override
	public void acitveClickStatistics() {
	/*	try {
			logger.info("处理每天的活动统计数据开始.....");
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar calendar = Calendar.getInstance();
			Date nowdate = new Date();
			calendar.setTime(nowdate);
			calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1);
			String date = sdf.format(calendar.getTime());
			String cachekey = "youGetMoneyMeRepayActivePageClickNum_" + date;
			List<String> clickdevices = jedisCluster.lrange(cachekey, 0, -1);
			int totalclicknum = 0;
			if (clickdevices == null || clickdevices.size() == 0) {
				logger.info("key:{}不存在活动统计数据...", date);
			} else {
				totalclicknum = clickdevices.size();
			}
			logger.info("{}查询出活动点击统计数据{}条....", date, totalclicknum);
			ActiveStatisticsInfo activeStatisticsInfo = new ActiveStatisticsInfo();
			activeStatisticsInfo.setActiveType("1");// 你借钱我来还活动
			long applycount = borrowStatisticsReportDao.selectTotalApplyforDay(sdf.format(calendar.getTime()));
			if (applycount != 0) {
				activeStatisticsInfo.setApplyNum(applycount);
			} else {
				activeStatisticsInfo.setApplyNum(0L);
			}
			long successcount = borrowStatisticsReportDao.selectTotalSuceesstforDay(sdf.format(calendar.getTime()));
			if (successcount != 0) {
				activeStatisticsInfo.setBorrowNum(successcount);
			} else {
				activeStatisticsInfo.setBorrowNum(0L);
			}
			activeStatisticsInfo.setClickNum(totalclicknum);
			activeStatisticsInfo.setCreateDate(nowdate);
			activeStatisticsInfo.setUpdateDate(nowdate);
			activeStatisticsInfo.setStatisticsDate(sdf.format(calendar.getTime()));
			activeStatisticsInfo.setIsDel("0");
			borrowStatisticsReportService.activeInsertBySelective(activeStatisticsInfo);
			logger.info("处理每天的活动统计数据完成.....");
		} catch (Exception e) {
			logger.error("新增活动统计数据异常....", e);
		}*/

	}
	//TODO-ZSH
	@Override
	public void queryOrderResult(String orderId) {
	/*	try {
			if (null == orderId || "".equals(orderId)) {
				logger.warn("订单结果查询接口,订单号为空");
				return;
			}
			// 获取富友订单查询接口路径
			String fuiouPath = FuYouConstant.getQueryOrderPath();//
			// 组装xml参数
			OrderQuerySend orderInfo = new OrderQuerySend();
			orderInfo.setMCHNTCD(FuYouConstant.getMchntcd()); //
			orderInfo.setMCHNTORDERID(orderId);
			orderInfo.setSIGN(orderInfo.toSign());
			String xmlParams = XmlUtil.toXml(OrderQuerySend.class, orderInfo);
			logger.info("订单结果查询接口,参数:" + xmlParams);

			List<NameValuePair> postParams = new ArrayList<NameValuePair>();
			postParams.add(new BasicNameValuePair("FM", xmlParams));

			// http形式调用接口得到结果
			String result = HttpUtil.getInstance().post(fuiouPath, postParams);
			logger.info("订单结果查询接口,结果:" + result);
			// 根据结果修改贷速侠数据状态，类似主动支付回调
			OrderQueryRecv orderQueryRecv = (OrderQueryRecv) XmlUtil.readMessage(OrderQueryRecv.class, result);

			OutOrders outOrders = outOrdersService.findByOrderNo(orderId);
			if (null != outOrders && (!OutOrders.STATUS_SUC.equals(outOrders.getStatus()))) {
				RepaymentDetail de = repaymentDetailService.selectByOrderId(orderId);
				if (null != de) {
					RepaymentDetail detail = new RepaymentDetail();
					detail.setId(de.getId());
					detail.setOrderId(orderId);

					OutOrders orders = new OutOrders();
					orders.setOrderNo(orderId);
					orders.setReturnParams(result);
					if (FuYouConstant.SUCCESS_CODE.equals(orderQueryRecv.getRESPONSECODE())) {
						Repayment re = repaymentService.selectByPrimaryKey(de.getAssetRepaymentId());

						detail.setStatus(RepaymentDetail.STATUS_SUC);
						orders.setStatus(OutOrders.STATUS_SUC);

						repaymentService.repay(re, de);

						// 如果是未逾期的还款，调用提额
						if (re.getLateDay() == 0) {
							User user = userService.searchByUserid(re.getUserId());
							logger.error("repay to Mention Money ing ----------------->");
							borrowOrderService.addUserLimit(user);
						}
					} else {
						detail.setStatus(RepaymentDetail.STATUS_OTHER);
						orders.setStatus(OutOrders.STATUS_OTHER);
					}
					repaymentDetailService.updateByPrimaryKeySelective(detail);
					outOrdersService.updateByOrderNo(orders);

					try {
						jedisCluster.del("FUYOU_REPAY_" + de.getAssetRepaymentId());
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					logger.warn("订单结果查询接口,贷速侠RepaymentDetail为空,订单号:" + orderId);
				}
			} else {
				logger.warn("订单结果查询接口,贷速侠OutOrders为空,订单号:" + orderId);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
*/
	}
	//TODO-ZSH
	public void queryOrderResultFuyou() {
		/*logger.error("富有查询订单开始-------------fuyou query start");
		try {
			Date endDate = new Date();
			Date begDate = DateUtil.addHour(endDate, -2); // 获取当前时间前2小时
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("begDate", begDate);
			params.put("endDate", endDate);
			params.put("status", 0);
			params.put("repaymentType", 2);
			List<RepaymentDetail> details = repaymentDetailService.queryOrderResult(params);
			logger.error("订单数量----------fuyou order number:" + details.size());
			for (RepaymentDetail pd : details) {
				this.queryOrderResult(String.valueOf(pd.getOrderId()));
			}
		} catch (Exception e) {
			logger.error("fuyou query error------", e);
			// e.printStackTrace();
		}*/
	}

	@Override
	public void pushZzcBlacklist() {
		logger.error("开始推送黑名单数据到中智诚-------------------------push Blacklist to zzc");
		try {
			Map<String, Object> params = new HashMap<>();
			List<HashMap<String, Object>> blackList = repaymentService.findBlackList(params);
			if (blackList.size() > 0) {
				for (HashMap<String, Object> map : blackList) {
					ServiceResult result = zzcService.setBlack(map);
					logger.info(result.getMsg());
				}
			}
		} catch (Exception e) {
			logger.error("ZZC set blanklist error ------", e);
		}

	}
	//TODO-ZSH
	@Override
	public void queryOrderResultLian() {
/*		logger.error("宝付、融宝 查询订单开始-------------baofu+rongbao query start");
		try {
			// Date endDate = new Date();
			// Date begDate = DateUtil.addHour(endDate, -2); //获取当前时间前2小时
			HashMap<String, Object> params = new HashMap<String, Object>();
			// params.put("begDate",begDate);
			// params.put("endDate",endDate);
			// params.put("repaymentType", 3);
			params.put("baoFuAndRongBao", 1);
			params.put("status", 0);
			List<RepaymentDetail> detail = repaymentDetailService.queryOrderResult(params);
			logger.error("订单数量----------baofu+rongbao  order number:" + detail.size());
			for (RepaymentDetail pd : detail) {
				repaymentService.queryWithhold(pd);
			}
		} catch (Exception e) {
			logger.error("baofu+rongbao_QUERY_RESULT ERROR........", e);
			e.printStackTrace();
		}
		logger.error("宝付、融宝查询订单结束-------------baofu+rongbao query end");*/
	}
	//TODO-ZSH
	public void queryRenewalOrder() {
		/*logger.info("用户处理中续期开始 queryRenewalOrder-------------start");
		try {
			List<RenewalRecord> list = renewalRecordService.queryRenewalOrder();
			logger.info("续期处理中数量----------" + list.size());
			for (RenewalRecord rr : list) {
				renewalRecordService.dealRenewalOrder(rr);
			}
		} catch (Exception e) {
			logger.error("续期处理 异常", e);
			e.printStackTrace();
		}
		logger.info("用户处理中续期结束 queryRenewalOrder-------------end");*/
	}
//TODO-ZSH
	public void zhimaDataBatchFeedback() {
		/*logger.info("芝麻反馈数据开始.....");
		zmservice.zhimaDataBatchFeedback();
		logger.info("芝麻反馈数据结束.....");*/

	}

	@Override
	public void updateLoanTermCallBack() {
		
		System.err.println("==============================");
	}

}
